<!DOCTYPE html>
<html>
<head>
	<title>杂物检测添加</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

    <title></title>
    <script src="js/mui.js"></script>
    <link href="css/mui.css" rel="stylesheet"/>
	<link href="css/common.css" rel="stylesheet"/>
	<link href="js/layui/css/layui.css" rel="stylesheet"/>
	<!-- Nicky -->
 	<link rel="stylesheet" href="css/nicky.css" />
 	<script src="js/jquery.min.js" ></script>
 	<script src="js/webdb.js"></script>
</head>
<body class="bg">
	<header class="mui-bar mui-bar-nav mui-bar-transparent bg main-header" >
	<div class="back"><a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left back" >返回</a></div>
	<div class="back" ><a class="mui-icon  mui-pull-center back" >杂物检测</a></div>

   </header>

	<div class="mui-content bg" style="margin-top:10px;" > 
		<div class="formBox formBox2">
			<p>
				<label>项目号</label>
				<input type="text" value="001" disabled="false" placeholder="请输入用户名" />
			</p>
			<p>
				<label>包重</label>
				<b class="one" id="bzl">0</b>
				<b id="getbzl">0</b>
				<a class="nbtn disable" id="btnGetbz">GET</a>
			</p>
			<p>
				<label>称重重量</label>
				<b class="one" id="zl">0</b>
				<b id="getzl">0</b>
				<a class="nbtn disable" id="btnGetzl">GET</a>
			</p>
			<p>
				<label>计重比例</label>
				<input type="text" id="bl" value="10" placeholder="请输入计重比例" />
			</p>
			<p>
				<label>质检员</label>
				<input type="text" id="uid" value="" placeholder="质检员" />
			</p>
			<p>
				<label>备注</label>
				<input type="text" id="beizu" value="备注" placeholder="请输入备注" />
			</p>
			 
		</div> 
		
		<div class="btnBox btnBox2"> 
			<button id="btnBack" class="nbtn">返 回</button> 
			<button id="btnSave" class="nbtn">保 存</button> 
		</div> 
		
     </div>
</form>
	</div>
	
<script>
var uid = null, uinfo = null, serverData=null , rowid = 0;
mui.init();
var old_back = null;
mui.plusReady(function(){
	
	old_back = mui.back;
	mui.back = function() {
		var wobj = plus.webview.getWebviewById("zwjc.html");
		wobj.reload(true);
		old_back();
	};
    //remove('zw',{},function(){});
    	
	uid = getSession('UID');
	uinfo = JSON.parse(getSession('UINFO'));
	serverData = JSON.parse(getSession('serData')); 
	
	var self = plus.webview.currentWebview();
	rowid = self.rowid;
	if(rowid){
		select('zw',TBS.zw,{where:{rowid:rowid}},function(dat){
			if(dat.length>0){
				var obj = dat.item(0);
				console.log(JSON.stringify(obj));
			}
		})
	};
	
	if(uinfo.USER2){
		$('#btnGetbz,#btnGetzl').removeClass('disable');
	}
	
	$('#btnGetbz,#btnGetzl').removeClass('disable');
	
	$('#btnGetbz').click(function(){
		if($(this).hasClass('disable')) return false;
		//获取地磅数据
		var val = parseInt(Math.random()*1000%100);
		$('#getbzl').text(val);
	});
	$('#btnGetzl').click(function(){
		if($(this).hasClass('disable')) return false;
		//获取地磅数据
		var val = parseInt(Math.random()*1000%100);
		$('#getzl').text(val);
		
		var baozhong =  parseInt($('#getbzl').text());
		var zawuzhong = parseInt($('#getzl').text());
		var bl = parseFloat(zawuzhong/baozhong*100).toFixed(2);
		$('#bl').val(bl);
	});

/*
BD_NO:磅单号
ITEM:行项目，回传SAP接口固定值"10"
BITEM:项目号
ZWZFL:"ZW"杂物
ZLYFS:来源方式，回传SAP接口固定值"A"
ZJNUM:上传人，用户表中的ID字段
ZWZBY:质检员，数据格式为“质检员编号\质检员姓名”，例："1\张三"
ZCLJG:杂物重量
ZJDBZ:包重
ZJSBL:杂物比例
ZFJBZ:是否复检，复检为"X"
BZTXT:备注
*/
	$('#btnSave').click(function(){
		var baozhong =  parseInt($('#getbzl').text());
		var zawuzhong = parseInt($('#getzl').text());
		var bl = parseFloat(zawuzhong/baozhong*100).toFixed(2);
		var dat = {BD_NO:serverData.bdid,ITEM:10,BITEM:0,ZWZFL:'ZW',ZLYFS:'A',ZJNUM:uid,ZWZBY:'12/质检员',ZCLJG:baozhong,ZJDBZ:zawuzhong,ZJSBL:bl,ZFJBZ:' ',BZTXT:$('#beizu').val()};
		var row = [];
		$.each(dat, function(i,d) {
			row.push(d);
		});
		
		if(rowid==1){
			console.log('==================='+rowid);
			console.log('Update Data');
			update('zw',dat,{rowid:rowid},function(row){
				mui.toast('更新成功');
				mui.back();
			});
		}else{
			console.log('+++++++++++++++++++'+rowid);
			console.log('Insert Data');
			insert('zw',TBS.zw,row,function(row){
				mui.toast('添加成功');
				mui.back();
			});
		}
		
		/*
		select('zw',TBS.zw,{},function(dat){
			for (var i=0;i<dat.length;i++) {
				console.log(JSON.stringify(dat.item(i)));
			}
		});
		*/
	});
	 
});
</script>
</body>
</html>